<?php


abstract class BaseClientsPeer {

	
	const DATABASE_NAME = 'propel';

	
	const TABLE_NAME = 'clients';

	
	const CLASS_DEFAULT = 'lib.model.Clients';

	
	const NUM_COLUMNS = 18;

	
	const NUM_LAZY_LOAD_COLUMNS = 0;


	
	const ID = 'clients.ID';

	
	const PRIORITY = 'clients.PRIORITY';

	
	const STATUS_ID = 'clients.STATUS_ID';

	
	const NAME = 'clients.NAME';

	
	const SURNAME = 'clients.SURNAME';

	
	const BIRTDAY = 'clients.BIRTDAY';

	
	const SEX = 'clients.SEX';

	
	const COUNTRY_CODE = 'clients.COUNTRY_CODE';

	
	const CITY = 'clients.CITY';

	
	const ADDRESS = 'clients.ADDRESS';

	
	const TELFAX = 'clients.TELFAX';

	
	const GSM = 'clients.GSM';

	
	const ZIP = 'clients.ZIP';

	
	const EMAIL = 'clients.EMAIL';

	
	const IS_COMPANY = 'clients.IS_COMPANY';

	
	const DEPARTMENT_ID = 'clients.DEPARTMENT_ID';

	
	const UPDATED_AT = 'clients.UPDATED_AT';

	
	const CREATED_AT = 'clients.CREATED_AT';

	
	private static $phpNameMap = null;


	
	private static $fieldNames = array (
		BasePeer::TYPE_PHPNAME => array ('Id', 'Priority', 'StatusId', 'Name', 'Surname', 'Birtday', 'Sex', 'CountryCode', 'City', 'Address', 'Telfax', 'Gsm', 'Zip', 'Email', 'IsCompany', 'DepartmentId', 'UpdatedAt', 'CreatedAt', ),
		BasePeer::TYPE_COLNAME => array (ClientsPeer::ID, ClientsPeer::PRIORITY, ClientsPeer::STATUS_ID, ClientsPeer::NAME, ClientsPeer::SURNAME, ClientsPeer::BIRTDAY, ClientsPeer::SEX, ClientsPeer::COUNTRY_CODE, ClientsPeer::CITY, ClientsPeer::ADDRESS, ClientsPeer::TELFAX, ClientsPeer::GSM, ClientsPeer::ZIP, ClientsPeer::EMAIL, ClientsPeer::IS_COMPANY, ClientsPeer::DEPARTMENT_ID, ClientsPeer::UPDATED_AT, ClientsPeer::CREATED_AT, ),
		BasePeer::TYPE_FIELDNAME => array ('id', 'priority', 'status_id', 'name', 'surname', 'birtday', 'sex', 'country_code', 'city', 'address', 'telfax', 'gsm', 'zip', 'email', 'is_company', 'department_id', 'updated_at', 'created_at', ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, )
	);

	
	private static $fieldKeys = array (
		BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Priority' => 1, 'StatusId' => 2, 'Name' => 3, 'Surname' => 4, 'Birtday' => 5, 'Sex' => 6, 'CountryCode' => 7, 'City' => 8, 'Address' => 9, 'Telfax' => 10, 'Gsm' => 11, 'Zip' => 12, 'Email' => 13, 'IsCompany' => 14, 'DepartmentId' => 15, 'UpdatedAt' => 16, 'CreatedAt' => 17, ),
		BasePeer::TYPE_COLNAME => array (ClientsPeer::ID => 0, ClientsPeer::PRIORITY => 1, ClientsPeer::STATUS_ID => 2, ClientsPeer::NAME => 3, ClientsPeer::SURNAME => 4, ClientsPeer::BIRTDAY => 5, ClientsPeer::SEX => 6, ClientsPeer::COUNTRY_CODE => 7, ClientsPeer::CITY => 8, ClientsPeer::ADDRESS => 9, ClientsPeer::TELFAX => 10, ClientsPeer::GSM => 11, ClientsPeer::ZIP => 12, ClientsPeer::EMAIL => 13, ClientsPeer::IS_COMPANY => 14, ClientsPeer::DEPARTMENT_ID => 15, ClientsPeer::UPDATED_AT => 16, ClientsPeer::CREATED_AT => 17, ),
		BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'priority' => 1, 'status_id' => 2, 'name' => 3, 'surname' => 4, 'birtday' => 5, 'sex' => 6, 'country_code' => 7, 'city' => 8, 'address' => 9, 'telfax' => 10, 'gsm' => 11, 'zip' => 12, 'email' => 13, 'is_company' => 14, 'department_id' => 15, 'updated_at' => 16, 'created_at' => 17, ),
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, )
	);

	
	public static function getMapBuilder()
	{
		include_once 'lib/model/map/ClientsMapBuilder.php';
		return BasePeer::getMapBuilder('lib.model.map.ClientsMapBuilder');
	}
	
	public static function getPhpNameMap()
	{
		if (self::$phpNameMap === null) {
			$map = ClientsPeer::getTableMap();
			$columns = $map->getColumns();
			$nameMap = array();
			foreach ($columns as $column) {
				$nameMap[$column->getPhpName()] = $column->getColumnName();
			}
			self::$phpNameMap = $nameMap;
		}
		return self::$phpNameMap;
	}
	
	static public function translateFieldName($name, $fromType, $toType)
	{
		$toNames = self::getFieldNames($toType);
		$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
		if ($key === null) {
			throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
		}
		return $toNames[$key];
	}

	

	static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
	{
		if (!array_key_exists($type, self::$fieldNames)) {
			throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
		}
		return self::$fieldNames[$type];
	}

	
	public static function alias($alias, $column)
	{
		return str_replace(ClientsPeer::TABLE_NAME.'.', $alias.'.', $column);
	}

	
	public static function addSelectColumns(Criteria $criteria)
	{

		$criteria->addSelectColumn(ClientsPeer::ID);

		$criteria->addSelectColumn(ClientsPeer::PRIORITY);

		$criteria->addSelectColumn(ClientsPeer::STATUS_ID);

		$criteria->addSelectColumn(ClientsPeer::NAME);

		$criteria->addSelectColumn(ClientsPeer::SURNAME);

		$criteria->addSelectColumn(ClientsPeer::BIRTDAY);

		$criteria->addSelectColumn(ClientsPeer::SEX);

		$criteria->addSelectColumn(ClientsPeer::COUNTRY_CODE);

		$criteria->addSelectColumn(ClientsPeer::CITY);

		$criteria->addSelectColumn(ClientsPeer::ADDRESS);

		$criteria->addSelectColumn(ClientsPeer::TELFAX);

		$criteria->addSelectColumn(ClientsPeer::GSM);

		$criteria->addSelectColumn(ClientsPeer::ZIP);

		$criteria->addSelectColumn(ClientsPeer::EMAIL);

		$criteria->addSelectColumn(ClientsPeer::IS_COMPANY);

		$criteria->addSelectColumn(ClientsPeer::DEPARTMENT_ID);

		$criteria->addSelectColumn(ClientsPeer::UPDATED_AT);

		$criteria->addSelectColumn(ClientsPeer::CREATED_AT);

	}

	const COUNT = 'COUNT(clients.ID)';
	const COUNT_DISTINCT = 'COUNT(DISTINCT clients.ID)';

	
	public static function doCount(Criteria $criteria, $distinct = false, $con = null)
	{
				$criteria = clone $criteria;

				$criteria->clearSelectColumns()->clearOrderByColumns();
		if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
			$criteria->addSelectColumn(ClientsPeer::COUNT_DISTINCT);
		} else {
			$criteria->addSelectColumn(ClientsPeer::COUNT);
		}

				foreach($criteria->getGroupByColumns() as $column)
		{
			$criteria->addSelectColumn($column);
		}

		$rs = ClientsPeer::doSelectRS($criteria, $con);
		if ($rs->next()) {
			return $rs->getInt(1);
		} else {
						return 0;
		}
	}
	
	public static function doSelectOne(Criteria $criteria, $con = null)
	{
		$critcopy = clone $criteria;
		$critcopy->setLimit(1);
		$objects = ClientsPeer::doSelect($critcopy, $con);
		if ($objects) {
			return $objects[0];
		}
		return null;
	}
	
	public static function doSelect(Criteria $criteria, $con = null)
	{
		return ClientsPeer::populateObjects(ClientsPeer::doSelectRS($criteria, $con));
	}
	
	public static function doSelectRS(Criteria $criteria, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		if (!$criteria->getSelectColumns()) {
			$criteria = clone $criteria;
			ClientsPeer::addSelectColumns($criteria);
		}

				$criteria->setDbName(self::DATABASE_NAME);

						return BasePeer::doSelect($criteria, $con);
	}
	
	public static function populateObjects(ResultSet $rs)
	{
		$results = array();
	
				$cls = ClientsPeer::getOMClass();
		$cls = Propel::import($cls);
				while($rs->next()) {
		
			$obj = new $cls();
			$obj->hydrate($rs);
			$results[] = $obj;
			
		}
		return $results;
	}

  
  public static function doSelectWithI18n(Criteria $c, $culture = null, $con = null)
  {
        $c = clone $c;
    if ($culture === null)
    {
      $culture = sfContext::getInstance()->getUser()->getCulture();
    }

        if ($c->getDbName() == Propel::getDefaultDB())
    {
      $c->setDbName(self::DATABASE_NAME);
    }

    ClientsPeer::addSelectColumns($c);
    $startcol = (ClientsPeer::NUM_COLUMNS - ClientsPeer::NUM_LAZY_LOAD_COLUMNS) + 1;

    ClientsI18nPeer::addSelectColumns($c);

    $c->addJoin(ClientsPeer::ID, ClientsI18nPeer::ID);
    $c->add(ClientsI18nPeer::CULTURE, $culture);

    $rs = BasePeer::doSelect($c, $con);
    $results = array();

    while($rs->next()) {

      $omClass = ClientsPeer::getOMClass();

      $cls = Propel::import($omClass);
      $obj1 = new $cls();
      $obj1->hydrate($rs);
      $obj1->setCulture($culture);

      $omClass = ClientsI18nPeer::getOMClass($rs, $startcol);

      $cls = Propel::import($omClass);
      $obj2 = new $cls();
      $obj2->hydrate($rs, $startcol);

      $obj1->setClientsI18nForCulture($obj2, $culture);
      $obj2->setClients($obj1);

      $results[] = $obj1;
    }
    return $results;
  }

	
	public static function getTableMap()
	{
		return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
	}

	
	public static function getOMClass()
	{
		return ClientsPeer::CLASS_DEFAULT;
	}

	
	public static function doInsert($values, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		if ($values instanceof Criteria) {
			$criteria = clone $values; 		} else {
			$criteria = $values->buildCriteria(); 		}

		$criteria->remove(ClientsPeer::ID); 

				$criteria->setDbName(self::DATABASE_NAME);

		try {
									$con->begin();
			$pk = BasePeer::doInsert($criteria, $con);
			$con->commit();
		} catch(PropelException $e) {
			$con->rollback();
			throw $e;
		}

		return $pk;
	}

	
	public static function doUpdate($values, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$selectCriteria = new Criteria(self::DATABASE_NAME);

		if ($values instanceof Criteria) {
			$criteria = clone $values; 
			$comparison = $criteria->getComparison(ClientsPeer::ID);
			$selectCriteria->add(ClientsPeer::ID, $criteria->remove(ClientsPeer::ID), $comparison);

		} else { 			$criteria = $values->buildCriteria(); 			$selectCriteria = $values->buildPkeyCriteria(); 		}

				$criteria->setDbName(self::DATABASE_NAME);

		return BasePeer::doUpdate($selectCriteria, $criteria, $con);
	}

	
	public static function doDeleteAll($con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}
		$affectedRows = 0; 		try {
									$con->begin();
			$affectedRows += ClientsPeer::doOnDeleteCascade(new Criteria(), $con);
			$affectedRows += BasePeer::doDeleteAll(ClientsPeer::TABLE_NAME, $con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	 public static function doDelete($values, $con = null)
	 {
		if ($con === null) {
			$con = Propel::getConnection(ClientsPeer::DATABASE_NAME);
		}

		if ($values instanceof Criteria) {
			$criteria = clone $values; 		} elseif ($values instanceof Clients) {

			$criteria = $values->buildPkeyCriteria();
		} else {
						$criteria = new Criteria(self::DATABASE_NAME);
			$criteria->add(ClientsPeer::ID, (array) $values, Criteria::IN);
		}

				$criteria->setDbName(self::DATABASE_NAME);

		$affectedRows = 0; 
		try {
									$con->begin();
			$affectedRows += ClientsPeer::doOnDeleteCascade($criteria, $con);
			$affectedRows += BasePeer::doDelete($criteria, $con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected static function doOnDeleteCascade(Criteria $criteria, Connection $con)
	{
				$affectedRows = 0;

				$objects = ClientsPeer::doSelect($criteria, $con);
		foreach($objects as $obj) {


			include_once 'lib/model/ClientsI18n.php';

						$c = new Criteria();
			
			$c->add(ClientsI18nPeer::ID, $obj->getId());
			$affectedRows += ClientsI18nPeer::doDelete($c, $con);
		}
		return $affectedRows;
	}

	
	public static function doValidate(Clients $obj, $cols = null)
	{
		$columns = array();

		if ($cols) {
			$dbMap = Propel::getDatabaseMap(ClientsPeer::DATABASE_NAME);
			$tableMap = $dbMap->getTable(ClientsPeer::TABLE_NAME);

			if (! is_array($cols)) {
				$cols = array($cols);
			}

			foreach($cols as $colName) {
				if ($tableMap->containsColumn($colName)) {
					$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
					$columns[$colName] = $obj->$get();
				}
			}
		} else {

		}

		$res =  BasePeer::doValidate(ClientsPeer::DATABASE_NAME, ClientsPeer::TABLE_NAME, $columns);
    if ($res !== true) {
        $request = sfContext::getInstance()->getRequest();
        foreach ($res as $failed) {
            $col = ClientsPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
            $request->setError($col, $failed->getMessage());
        }
    }

    return $res;
	}

	
	public static function retrieveByPK($pk, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$criteria = new Criteria(ClientsPeer::DATABASE_NAME);

		$criteria->add(ClientsPeer::ID, $pk);


		$v = ClientsPeer::doSelect($criteria, $con);

		return !empty($v) > 0 ? $v[0] : null;
	}

	
	public static function retrieveByPKs($pks, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection(self::DATABASE_NAME);
		}

		$objs = null;
		if (empty($pks)) {
			$objs = array();
		} else {
			$criteria = new Criteria();
			$criteria->add(ClientsPeer::ID, $pks, Criteria::IN);
			$objs = ClientsPeer::doSelect($criteria, $con);
		}
		return $objs;
	}

} 
if (Propel::isInit()) {
			try {
		BaseClientsPeer::getMapBuilder();
	} catch (Exception $e) {
		Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
	}
} else {
			require_once 'lib/model/map/ClientsMapBuilder.php';
	Propel::registerMapBuilder('lib.model.map.ClientsMapBuilder');
}
